# name : proc means(autoname)+tranpose (numeric)
# key : proc.means.autoname.transpose.numeric
# contributor: Shuguang Sun
# --
/* Request statistics on the OUTPUT statement. */
/* Use the AUTONAME option to create variable names in the form: */
/* variable_statistic */
proc means data=${1:din} noprint;
  format ${2:group} $ogroup.;
  class $2 / order = formatted;
  var ${3:var};
  by ${4:avisit};
  output out = ${5:_out1} n= mean= std= median= q1= q3= min= max=/ autoname;
  where ;
run;

/* total */
data $5 (drop=_type_ _freq_);
  set $5;
  if _type_ eq 0 then $2 = "Total";
run;

/* Transpose the data set so that each statistic becomes an observation. */
proc transpose data=$5 out=${6:_out2};
  format ${2:group} $group.;
  var _numeric_;
  id $2;
  by $4;
run;

/* Create new variables that contain the statistic name and the */
/* original variable name. */
data ${7:dout};
  set $6;
  varname = scan(_name_,1,'_');
  stat = scan(_name_,2,'_');
  drop _name_;
run;

proc sort data=$7;
  by $4 varname;
run;

proc print data=$7 noobs;
  format _numeric_ 10.2;
  var $4 stat _numeric_;
  title "$0";
run;
